package com.yy.wga.pay.service.client.request.wechat;

import com.alibaba.fastjson.annotation.JSONField;
import com.yy.wga.pay.service.client.request.BasePreOrderRequest;
import com.yy.wga.pay.service.client.response.wechat.WechatAppPreOrderResponse;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import javax.validation.constraints.NotBlank;

/**
 * @Author: gc
 * @Date: 2021/6/13
 * @Description:
 **/
@EqualsAndHashCode(callSuper = true)
@Data
@ToString(callSuper = true)
public class WechatAppPreOrderRequest extends BasePreOrderRequest<WechatAppPreOrderResponse> {
    private static final long serialVersionUID = 4512706488463641745L;

    /**
     * 由微信生成的应用ID
     */
    @JSONField(name = "appid")
    private String appId;

    /**
     * 直连商户的商户号，由微信支付生成并下发。
     */
    @JSONField(name = "mchid")
    private String mchId;

    /**
     * 商品描述
     */
    private String description;

    /**
     * 内部订单号
     */
    @JSONField(name = "out_trade_no")
    @NotBlank(message = "订单号为空")
    private String outTradeNo;

    /**
     * 交易结束时间
     */
    @JSONField(name = "time_expire")
    private String timeExpire;

    /**
     * 附加数据，在查询API和支付通知中原样返回，可作为自定义参数使用
     * 示例值：自定义数据
     */
    private String attach;

    /**
     * 异步通知地址为空
     */
    @JSONField(name = "notify_url")
    private String notifyUrl;

    /**
     * 订单优惠标记
     */
    private String goodsTag;

    /**
     * 订单金额信息
     */
    private Amount amount;

    /**
     * 优惠功能
     */
    private Detail detail;

    /**
     * 支付场景描述
     */
    @JSONField(name = "scene_info")
    private SceneInfo sceneInfo;

    /**
     * 结算信息
     */
    @JSONField(name = "settle_info")
    private SettleInfo settleInfo;

    @Data
    public static class Amount {

        /**
         * 总金额
         */
        private Long total;
        /**
         * 货币类型
         */
        private String currency;
    }

    @Data
    public static class Detail {

        /**
         * 订单原价
         */
        @JSONField(name = "cost_price")
        private Integer costPrice;
        /**
         * 商品小票ID
         */
        @JSONField(name = "invoice_id")
        private String invoiceId;

        /**
         * 单品列表
         */
        @JSONField(name = "goods_detail")
        private GoodsDetail goodsDetail;

        @Data
        public static class GoodsDetail {

            /**
             * 商户侧商品编码
             */
            @JSONField(name = "merchant_goods_id")
            private String merchantGoodsId;

            /**
             * 微信侧商品编码
             */
            @JSONField(name = "wechatpay_goods_id")
            private String wechatpayGoodsId;

            /**
             * 商品名称
             */
            @JSONField(name = "goods_name")
            private String goodsName;

            /**
             * 商品数量
             */
            private Integer quantity;

            /**
             * 商品单价
             */
            @JSONField(name = "unit_price")
            private Integer unit_price;
        }
    }

    @Data
    public static class SceneInfo {

        /**
         * 用户终端IP
         */
        @JSONField(name = "payer_client_ip")
        private String payerClientIp;

        /**
         * 商户端设备号
         */
        @JSONField(name = "device_id")
        private String deviceId;

        /**
         * 商户门店信息
         */
        @JSONField(name = "store_info")
        private StoreInfo storeInfo;

        @Data
        public static class StoreInfo {

            /**
             * 门店编号
             */
            private String id;

            /**
             * 门店名称
             */
            @JSONField(name = "name")
            private String name;

            /**
             * 地区编码，详细请见https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/applyments/chapter4_1.shtml
             */
            @JSONField(name = "area_code")
            private String areaCode;

            /**
             * 详细地址
             */
            private String address;
        }
    }

    @Data
    public static class SettleInfo {

        /**
         * 是否指定分账
         */
        @JSONField(name = "profit_sharing")
        private Boolean profit_sharing;
    }
}
